<?php

namespace App\Http\Controllers\Admin;

use App\Models\AdminPermission;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PermissionController extends Controller
{
    public function index() {
        $permissions  = AdminPermission::paginate(10);
        return view('admin.permission.index',compact('permissions'));
    }

    public function create() {
        return view('admin.permission.create');
    }

    public function doCreate(Request $request) {
        $this->validate($request,[
            'name'       => 'required',
            'description'=> 'required'
        ]);

        $new_permission = AdminPermission::create($request->input());
        if(!empty($new_permission)){
            return redirect('admin/permission')->with('创建权限成功!');
        }else{
            return back()->withErrors('创建权限失败!');
        }
    }
}
